<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.wxtf.platform.plugins.user.*"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
UserBean user = (UserBean)request.getSession().getAttribute("userBean");

String _db = user.getDbType();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<base href="<%=basePath%>" />

		<meta http-equiv="X-UA-Compatible" content="IE=edge" />
		<link type="text/css" rel="stylesheet" href="ligerUI/skins/Aqua/css/ligerui-all.css" />
		<link type="text/css" rel="stylesheet" href="ligerUI/skins/<%=user.getUserCss()%>/css/ligerui-all.css" />
		<link type="text/css" rel="stylesheet" href="ligerUI/skins/ligerui-icons.css" />
		<link type="text/css" rel="stylesheet" href="resource/css/style.css" />

		<script type="text/javascript" src="js/jquery/jquery-1.7.2.js"></script>
		<script type="text/javascript" src="ligerUI/js/core/base.js"></script>
		<script type="text/javascript" src="ligerUI/js/ligerui.min.js"></script>

		<script type="text/javascript" src="ligerUI/js/plugins/ligerGrid.js"></script>
		<script type="text/javascript" src="ligerUI/js/plugins/ligerTree.js"></script>

		<script type="text/javascript" src="js/common.js"></script>
		<script type="text/javascript" src="js/validata.js"></script>
		<script type="text/javascript" src="js/json2.js"></script>
		<script>
		var _db = '<%=_db%>';
		
			//全局变量 本页面使用
		    var totalUserGridDatas = 0;
		    var globleUserId ;
		    var globleUserName ;
		    var globleGroupNames = "";
		    var globleOrgNames  = "";
		    var globleRoleNames  = "";
					    
			var arraySerarchList = new Array();		    
			
			//查询使用
			var searchJsonObj = { 
				"classname": "com.wxtf.platform.plugins.user.UserAction",
				"methodname": "queryPage",
				"logicdata": "[]",
				"extenddata": "[]"
			};
			
			//增加使用
			var addJsonObj = { 
				"classname": "com.wxtf.platform.plugins.user.UserAction",
				"methodname": "queryPage",
				"logicdata": "[]",
				"extenddata": "[]"
			};
			
			//修改使用
			var updateJsonObj = { 
				"classname": "com.wxtf.platform.plugins.user.UserAction",
				"methodname": "queryPage",
				"logicdata": "[]",
				"extenddata": "[]"
			};
			
			//删除使用
			var deleteJsonObj = { 
				"classname": "com.wxtf.platform.plugins.user.UserAction",
				"methodname": "queryPage",
				"logicdata": "[]",
				"extenddata": "[]"
			};
			
			//树查询使用
			var treeSearchJsonObj = { 
				"classname": "com.wxtf.platform.plugins.group.GroupAction",
				"methodname": "queryPage",
				"logicdata": "[]",
				"extenddata": "[]"
			};
			
			//用户已有角色查询
			var roleHaveJsonObj = { 
				"classname": "com.wxtf.platform.plugins.user.UserAction",
				"methodname": "listRole",
				"logicdata": "[]",
				"extenddata": "[]"
			};
			
			//用户所有角色查询
			var roleAllJsonObj = { 
				"classname": "com.wxtf.platform.plugins.user.UserAction",
				"methodname": "listRole",
				"logicdata": "[]",
				"extenddata": "[]"
			};
			
			//用户所有角色查询
			var roleControlJsonObj = { 
				"classname": "com.wxtf.platform.plugins.user.UserAction",
				"methodname": "listRole",
				"logicdata": "[]",
				"extenddata": "[]"
			};
			
			//增加窗口
			var win;
			var winTotalUserAdd;
			var winUserAndGroup;
			var winUserAndRole;
			var winUserAndOrg;
			var winTallSearch;
			
			//grid对象
			var userGrid;
			var userHaveRoleGrid;
			var userAllRoleGrid;
			
			//tree对象userGroup
			var userGroupTreeObj;
			var userOrgTreeObj;
			
	
$(function (){
		userGrid = $("#user_grid").ligerGrid({
                url : _url, parms: searchJsonObj,
                height:'100%',checkbox:true,rownumbers:true,
                columns: [
                { display:'用户ID', name:'user_id',hide:true,width:1},
                { display:'登录账户', name:'action',align: 'center',width: 200},
                { display:'显示名称', name:'caption',align: 'center',width: 200},
                {
                    display: '用户状态', name: 'user_status',width: 100, isSort:false,
                    render: function (row)
                    {
                       var html = '<font color="red">登录受限</font>';
                       if(row.user_status=='0'){
                       		html = '<font color="red">登录受限</font>';
                       }else if(row.user_status=='1'){
                       		html = '<font color="green">登录许可</font>';
                       }
                       return html;
                    }
                },
                { display:'用户样式', name:'real_name',hide:true,align: 'center',width:1},
                { display:'用户邮箱', name:'user_email',hide:true,align: 'center',width:1},
                { display:'用户密码', name:'user_passwd',align: 'center',hide:true,width:1},
                { display:'办公电话', name:'user_office_tel',hide:true,align: 'center',width:1},
                { display:'家庭电话', name:'user_tel',hide:true,align: 'center',width:1},
                { display:'fax', name:'user_fax',hide:true,align: 'center',width:1},
                { display:'住址', name:'user_address',hide:true,align: 'center',width:1},
                { display:'创建', name:'user_created',hide:true,align: 'center',width:1},
                { display:'修改', name:'user_modified',hide:true,align: 'center',width:1},
                { display:'memo1', name:'user_memo1',hide:true,align: 'center',width:1},
                { display:'移动电话', name:'user_mobilephone',hide:true,align: 'center',width:1},
                { display:'postal', name:'user_postal',hide:true,align: 'center',width:1},
                { display:'用户性别', name:'user_sex',hide:true,align: 'center',width:1},
                { display:'出生日期', name:'user_birthday',hide:true,align: 'center',width:1},
                { display:'education', name:'user_education',hide:true,align: 'center',width:1},
                { display:'position', name:'user_position_id',hide:true,align: 'center',width:1},
                { display:'uparent', name:'uparent_id',hide:true, align: 'center',width:1},
                { display:'logic_code', name:'logic_code',align: 'center',hide:true,width:1},
                {
                    display: '修改', name: 'user_id',width: 60,isSort:false,
                    render: function (row){
                       return "<img src='ligerUI/skins/icons/edit.gif' onclick='userUpdate("+JSON.stringify(row)+")'></img>";
                    }
                },{
                    display: '选择部门', name: 'user_id',width: 80,isSort:false,
                    render: function (row){
                       return "<img src='ligerUI/skins/icons/bluebook.gif' onclick='showUserOrg(\""+row.user_id+"\",\""+row.caption+"\")'></img>";
                    }
                },{
                    display: '选择用户组', name: 'user_id',width: 80,isSort:false,
                    render: function (row){
                       return "<img src='ligerUI/skins/icons/msn.gif' onclick='showUserGroup(\""+row.user_id+"\",\""+row.caption+"\")'></img>";
                    }
                },{
                    display: '选择角色', name: 'user_id',width: 80,isSort:false,
                    render: function (row){
                       return "<img src='ligerUI/skins/icons/role.gif' onclick='showUserRole(\""+row.user_id+"\",\""+row.caption+"\")'></img>";
                    }
                },{
                    display: '选择菜单', name: 'user_id',width: 80,isSort:false,
                    render: function (row){
                       return "<img src='ligerUI/skins/icons/archives.gif' onclick='showUserMenu(\""+row.user_id+"\")'></img>";
                    }
                }],
                
                toolbar: {
                	items: [
		                { text: '批量新建', click: totalUserAdd, icon: 'add' },
		                { line: true },
		                { text: '新建', click: userAdd, icon: 'add' },
		                { line: true },
		                { text: '删除', click: userDelete,icon: 'delete'},
		                { line: true },
		                { text: '登录许可', click: userAcessLogin,icon: 'ok'},
		                { line: true },
		                { text: '登录受限', click: userAcessNotLogin,icon: 'busy'},
		                { line: true },
		                { text: '重置密码', click: userPasswordReset,icon: 'ok'}
	                ]
                }
            });
            
            
        });
		
		//用户新建
		function userAdd(){
			document.getElementById('user_addform').reset();
			$("#f_a_user_id").val('');
			if(win==null){
	            win = initWindowByDiv('userAdd', '新建窗口', 400, 300 ,controlFormUserAdd,closeWin);
			}else{
				win.show();
			}
		}
		
		//用户新建 窗口确认按钮
        function controlFormUserAdd(){
        	var userId = $("#f_a_user_id").val();
        	var action = $("#f_a_action").val().trim();//登录账号
        	var caption = $("#f_a_caption").val().trim();//显示名称
        	var sex = $("#f_a_user_sex").val().trim();
        	var birthday = $("#f_a_user_birthday").val().trim();
        	
        	var email = $("#f_a_user_email").val().trim();
        	var office_tel = $("#f_a_user_office_tel").val().trim();
        	var user_tel = $("#f_a_user_tel").val().trim();
        	var user_fax = $("#f_a_user_fax").val().trim();
        	var address = $("#f_a_user_address").val().trim();
        	var mobilephone = $("#f_a_user_mobilephone").val().trim();
        	
        	if(fucCheckLength(action) <= 0 || fucCheckLength(action) > 50){
				warningTip("登录账号：不能为空且不能超过50字符");
				return;
			}
			if(!checkIsString(action)){
				warningTip("登录账号：只能由字母、数字、下划线组成，并且不能以数字开头");
				return;
			}
        	if(fucCheckLength(caption) <= 0 || fucCheckLength(caption) > 150){
				warningTip("显示名称：不能为空且不能超过150字符");
				return;
			}
			if(!checkIsString(caption)){
				warningTip("显示名称：只能由字母、数字、下划线组成");
				return;
			}
        	if(fucCheckLength(mobilephone) > 50){
				warningTip("移动电话：不能超过50字符");
				return;
			}
			if(!checkIsMobile(mobilephone)){
				warningTip("移动电话：格式不正确，如13904318888");
				return;
			}
        	if(fucCheckLength(office_tel) > 50){
				warningTip("办公电话：不能超过50字符");
				return;
			}
			if(!checkIsTelephone(office_tel)){
				warningTip("办公电话：格式不正确，如0431-87654321-1234");
				return;
			}
        	if(fucCheckLength(user_tel) > 50){
				warningTip("家庭电话：不能超过50字符");
				return;
			}
			if(!checkIsTelephone(user_tel)){
				warningTip("家庭电话：格式不正确，如0431-87654321");
				return;
			}
        	if(fucCheckLength(email) > 50){
				warningTip("邮箱：不能超过50字符");
				return;
			}
        	if(!checkIsEmail(email)){
				warningTip("邮箱：格式不正确，如example@163.com");
				return;
			}
			
	     	var tempDatas = "[{\"user_id\":\"" + userId;
			tempDatas+="\",\"uparent_id\":\"0";
			tempDatas+="\",\"caption\":\"" + caption;
			tempDatas+="\",\"logic_code\":\"";
			tempDatas+="\",\"user_status\":\"0";
			tempDatas+="\",\"real_name\":\"Aqua";
			tempDatas+="\",\"user_email\":\""+ email;
			tempDatas+="\",\"user_passwd\":\"";
			tempDatas+="\",\"user_office_tel\":\""+ office_tel;
			tempDatas+="\",\"user_tel\":\""+ user_tel;
			tempDatas+="\",\"user_fax\":\""+ user_fax;
			tempDatas+="\",\"user_address\":\""+ address;
			tempDatas+="\",\"user_created\":\"";
			tempDatas+="\",\"user_modified\":\"" + getCurDateTime();
			tempDatas+="\",\"user_memo1\":\"";
			tempDatas+="\",\"user_mobilephone\":\""+ mobilephone;
			tempDatas+="\",\"user_postal\":\"";
			tempDatas+="\",\"user_sex\":\""+ sex;
			tempDatas+="\",\"user_birthday\":\""+ birthday;
			tempDatas+="\",\"user_education\":\"index.jsp";
			tempDatas+="\",\"user_position_id\":\"";
			tempDatas+="\",\"action\":\""+ action +"\"}]";
        	
        	if(userId == ''){
	        	addJsonObj.classname = "com.wxtf.platform.plugins.user.UserAction";
				addJsonObj.methodname = "save";
				addJsonObj.logicdata = tempDatas
				addJsonObj.extenddata = '[]';
				callserver(addJsonObj,formUserAddSuc,formUserAddErr);
        	}else{
				updateJsonObj.classname = "com.wxtf.platform.plugins.user.UserAction";
				updateJsonObj.methodname = "updateUser";
				updateJsonObj.logicdata = tempDatas;
				updateJsonObj.extenddata = "[]";
				callserver(updateJsonObj,formUserUpdateSuc,formUserUpdateErr);
        	}
        }
        
        //成功
        function formUserAddSuc(data, textStatus){
        	win.hide();
        	succMsgTip(data.resultrecord);
        	userGrid.loadData();
        }
        //失败
        function formUserAddErr(data, textStatus){
        	win.hide();
        	warningTip('失败添加【'+$("#f_a_action").val()+'】账户');
        	userGrid.loadData();
        }
		
		//用户批量新建
		function totalUserAdd(){
			if(winTotalUserAdd==null){
	            winTotalUserAdd = initWindowByDiv('totalUserAdd','批量新建', 300, 200,controlTotalUserAdd, closeWin);
			}else{
				winTotalUserAdd.show();
			}
		}
		//回调函数
		function controlTotalUserAdd(){
			var num = $("#totalUserAddNum").val().trim();
			var preFix = $("#totalUserAddPrefix").val().trim();
			if(num == ''){
				warningTip("新建数目：不能为空");
				return;
			}
			if(!checkIsNum(num)){
				warningTip("新建数目：必须为数字");
				return;
			}
			if(parseInt(num) > 1000){
				warningTip("新建数目：不能超过1000个");
				return;
			}
			if(!checkIsStrNumLine(preFix)){
				warningTip("账户前缀：必须是字母、数字、下划线或其组合");
				return;
			}
			
		    if(preFix == ""){
		    	$.ligerDialog.confirm('确认不使用前缀码？', function (ml) {
		    		if(ml==true){
						addJsonObj.methodname = "totalInsert";
						addJsonObj.logicdata =  '[{"total":"'+ num +'","preFix":""}]';
						callserver(addJsonObj,totalUserAddSuc,totalUserAddErr);
		    		}
		    	}); 
		    } else {
    			addJsonObj.methodname = "totalInsert";
				addJsonObj.logicdata =  '[{"total":"'+ num +'","preFix":"'+ preFix +'"}]'
				callserver(addJsonObj,totalUserAddSuc,totalUserAddErr);
		    }
		}
		
		//回调函数
		function totalUserAddSuc(){
			winTotalUserAdd.hide();
			succMsgTip('操作成功');
			userGrid.loadData();
		}
		
		//回调函数
		function totalUserAddErr(){
			winTotalUserAdd.hide();
			warningTip('操作失败');
		}
		
		//用户修改
		function userUpdate(userRowData){
			document.getElementById('user_addform').reset();
			
			$("#f_a_user_id").val(userRowData.user_id);
			$("#f_a_caption").val(userRowData.caption);
			$("#f_a_real_name").val(userRowData.real_name);
			$("#f_a_user_email").val(userRowData.user_email);
			$("#f_a_user_office_tel").val(userRowData.user_office_tel);
			$("#f_a_user_tel").val(userRowData.user_tel);
			$("#f_a_user_address").val(userRowData.user_address);
			$("#f_a_user_mobilephone").val(userRowData.user_mobilephone);
			$("#f_a_user_sex").val(userRowData.user_sex);
			$("#f_a_action").val(userRowData.action);
		
			if(win==null){
	            win = initWindowByDiv('userAdd','修改窗口', 400, 300,controlFormUserAdd,closeWin);
			}else{
				win.show();
			}
		}
		
		//用户修改 成功回调函数
		function formUserUpdateSuc(data, textStatus){
			succMsgTip(data.resultrecord);
			win.hide();
			userGrid.loadData();
		}
		
		//用户修改 失败回调函数
		function formUserUpdateErr(data, textStatus){
			warningTip('修改用户失败');
		}
		
		//删除用户 
		function userDelete(){
			var userIds = getUserIds(false);
			if(userIds == ""){
				warningTip('请至少选则一个用户进行操作');
				return;
			}
       		var notLoginNames= getUserCaptions();
			$.ligerDialog.confirm('确认进行删除操作？', function (ml) { 			
				if(ml==true){
		       		if(userIds!=""){
						updateJsonObj.classname = "com.wxtf.platform.plugins.user.UserAction";
						updateJsonObj.methodname = "delete";
						updateJsonObj.logicdata = "[{\"ids\":\""+userIds+"\"}]";
						updateJsonObj.extenddata = "[]";
						callserver(updateJsonObj,formUserDeleteSuc,formUserDeleteErr);
					}
				}
			});
				
		}
		//删除用户   成功回调函数
		function formUserDeleteSuc(){
			var userNames =  getUserCaptions();
			succMsgTip('删除用户成功');
			userGrid.loadData();
		}
		
		//删除用户   失败回调函数
		function formUserDeleteErr(){
			var userNames =  getUserCaptions();
			warningTip('删除用户失败');
		}
        
        //登录受限 授权方法
        function userAcessNotLogin(){
       		var notLoginIds = getUserIds(false);
			if(notLoginIds == ""){
				warningTip('请至少选则一个用户进行操作');
				return;
			}
       		
       		var notLoginNames= getUserCaptions();
			$.ligerDialog.confirm('确认进行授权操作？', function (ml) { 
				if(ml==true){
		       		if(notLoginIds!=""){
						updateJsonObj.classname = "com.wxtf.platform.plugins.user.UserAction";
						updateJsonObj.methodname = "userAcessNotLogin";
						updateJsonObj.logicdata = "[{\"ids\":\""+notLoginIds+"\"}]";
						updateJsonObj.extenddata = "[]";
						callserver(updateJsonObj,formUserNotLoginSuc,formUserNotLoginErr);
					}
				}
			});
        }
        
        //登录受限 成功回调函数
        function formUserNotLoginSuc(){
            var notLoginNames= getUserCaptions();
       		if(notLoginNames!=""){
        		succMsgTip('登录受限授权成功');
        	}
        	userGrid.loadData();
        }
        
        //登录受限 失败回调函数
        function formUserNotLoginErr(){
            var notLoginNames= getUserCaptions();
       		if(notLoginNames!=""){
        		warningTip('登录受限授权失败');
        	}
        }
        
        //登录许可 授权方法
        function userAcessLogin(){
       		var loginIds = getUserIds(false);
			if(loginIds == ""){
				warningTip('请至少选则一个用户进行操作');
				return;
			}
       		var Names= getUserCaptions();
			$.ligerDialog.confirm('确认进行的授权操作？', function (ml) { 
				if(ml){
		       		if(loginIds!=""){
						updateJsonObj.classname = "com.wxtf.platform.plugins.user.UserAction";
						updateJsonObj.methodname = "userAcessLogin";
						updateJsonObj.logicdata = "[{\"ids\":\""+loginIds+"\"}]";
						updateJsonObj.extenddata = "[]";
						
						callserver(updateJsonObj,formUserLoginSuc,formUserLoginErr);
					}
				}
			});
			
        }
        //登录许可 成功回调函数
        function formUserLoginSuc(){
            var loginNames= getUserCaptions();
       		if(loginNames!=""){
        		succMsgTip('登录许可成功');
        	}
        	userGrid.loadData();
        }
        
        
        //登录许可 失败回调函数
        function formUserLoginErr(){
			var loginNames= getUserCaptions();
       		if(loginNames!=""){
        		warningTip('登录许可失败');
        	}
        }
        
        //获得选中用户的登录名称集合
        function getUserCaptions(){
			var arrayUsers = userGrid.getSelecteds();
			if(arrayUsers.length==0){
				warningTip('请至少选则一个用户进行操作');
				return "";
			}else{
				var text="";
				for(var i=0;i<arrayUsers.length;i++){
					text += arrayUsers[i].caption+",";
				}
				return text.substring(0,text.length-1);
			}  
        }
        //获得选中用户的登录ID集合
        function getUserIds(flag){
            var arrayUsers = userGrid.getSelecteds();
			if(arrayUsers.length==0){
				return "";
			}else{
				var text="";
				for(var i=0;i<arrayUsers.length;i++){
					var id = arrayUsers[i].user_id;
					if(id == '0' || id == 0){
						if(!flag){
							continue;
						}
					}
					text += id + ",";
				}
				return text.substring(0,text.length-1);
			}        
        }
        
        //查询
        function searchBycols(){
        	var userName = $("#search_userName").val();
        	var loginName = $("#search_loginName").val();
        	
			searchJsonObj.classname = "com.wxtf.platform.plugins.user.UserAction";
			searchJsonObj.methodname = "queryPage";
			searchJsonObj.extenddata = "[{\"search_userName\":\""+userName+"\",\"search_loginName\":\""+loginName+"\"}]";
			searchJsonObj.logicdata = "[]";
			
        	callserver(searchJsonObj,formUserSearchSuc,formUserSearchErr);
        }
        
        //回调函数
        function formUserSearchSuc(){
			userGrid.loadData();
			succMsgTip('查询用户成功');
        }
        
        function formUserSearchErr(){
			userGrid.loadData();
			warningTip('查询用户失败');
        }
        
        //用户绑定机构
        function showUserOrg(userId,userName){
			treeSearchJsonObj.classname = "com.wxtf.platform.plugins.org.OrgAction";
			treeSearchJsonObj.methodname = "listOrg";
			treeSearchJsonObj.logicdata = "[{\"user_id\":\""+userId+"\",\"name\":\"\"}]";
			treeSearchJsonObj.extendata = "[]";
			
   			if(userOrgTreeObj!=null)userOrgTreeObj.clear();
   		    userOrgTreeObj = $("#userBYOrgTree").ligerTree({
   				checkbox : true,autoCheckboxEven:false,
   				nodeWidth: 300
   			});
   			
   			userOrgTreeObj.loadData('',_url,treeSearchJsonObj);
   			
        	globleUserId = userId;
        	globleUserName = userName;
        	if(winUserAndOrg==null){
	            winUserAndOrg = initWindowByDiv('userBYOrgTree','绑定部门', 500, 400,controlShowUserOrg,closeWin);
			}else{
				winUserAndOrg.show();
			}
        }
        
        //用户机构分配
        function controlShowUserOrg(){
        	var treeJsons = userOrgTreeObj.getCheckeds();
        	var pids = ""; 
        	for(var i=0;i<treeJsons.length;i++){
        		pids += treeJsons[i].data.id+",";
        		globleOrgNames += treeJsons[i].data.text+",";
        	}
        	
        	treeSearchJsonObj.classname = "com.wxtf.platform.plugins.user.UserAction";
			treeSearchJsonObj.methodname = "saveOrg";
			treeSearchJsonObj.logicdata = "[{\"user_id\":\""+globleUserId+"\",\"org_id\":\""+pids.substring(0,pids.length-1)+"\"}]";
			treeSearchJsonObj.extendata = "[]";
		
			callserver(treeSearchJsonObj,saveUserOrgSuc,saveUserOrgErr);
        }
        
        //保存用户组成功回调函数
        function saveUserOrgSuc(){
        	winUserAndOrg.hide();
        	succMsgTip('分配部门成功');
        }
        
        //失败回调函数
        function saveUserOrgErr(){
        	winUserAndOrg.hide();
        	warningTip('分配部门成功');
        }
        
        //用户绑定用户组
        function showUserGroup(userId,userName){
			treeSearchJsonObj.classname = "com.wxtf.platform.plugins.group.GroupAction";
			treeSearchJsonObj.methodname = "listGroup4User";
			treeSearchJsonObj.logicdata = "[{\"user_id\":\""+userId+"\",\"name\":\"\"}]";
			treeSearchJsonObj.extendata = "[]";
			
   			if(userGroupTreeObj!=null)userGroupTreeObj.clear();
   		    userGroupTreeObj = $("#userBYGroupTree").ligerTree({
   				checkbox: true,
   				nodeWidth: 300   				
   			});
   			
   			userGroupTreeObj.loadData('',_url,treeSearchJsonObj);
   			
        	globleUserId = userId;
        	globleUserName = userName;
        	if(winUserAndGroup==null){
	            winUserAndGroup = initWindowByDiv('userBYGroupTree','绑定用户组', 500, 400,controlShowUserGroup,closeWin);
			}else{
				winUserAndGroup.show();
			}
       		
        }
        
        //确认分配调用的事件
        function controlShowUserGroup(){
        	var treeJsons = userGroupTreeObj.getCheckeds();
        	var pids = ""; 
        	for(var i=0;i<treeJsons.length;i++){
        		pids += treeJsons[i].data.id+",";
        		globleGroupNames += treeJsons[i].data.text+",";
        	}
        	
        	treeSearchJsonObj.classname = "com.wxtf.platform.plugins.user.UserAction";
			treeSearchJsonObj.methodname = "saveGroup";
			treeSearchJsonObj.logicdata = "[{\"user_id\":\""+globleUserId+"\",\"group_id\":\""+pids.substring(0,pids.length-1)+"\"}]";
			treeSearchJsonObj.extendata = "[]";
		
			callserver(treeSearchJsonObj,saveUserGroupSuc,function(){});
        	
        }
        
        //保存用户组成功回调函数
        function saveUserGroupSuc(){
        	winUserAndGroup.hide();
        	succMsgTip('分配组成功');
        }
        
        function showUserRole(userId,userName){
        	globleUserId = userId;
        	globleUserName = userName;
        	if(winUserAndRole==null){
	            winUserAndRole = initWindowByDiv2('winUserAndRole','角色绑定', 800, 428,cancelShowUserRole);
			}else{
				winUserAndRole.show();
			}
			
            roleHaveJsonObj.methodname = "listRole4User";
			roleHaveJsonObj.logicdata = "[{\"user_id\":\""+userId+"\",\"name\":\"\"}]";
			
			userHaveRoleGrid = $("#userHaveRoleGrid").ligerGrid({
            	url: _url, parms: roleHaveJsonObj,
				width: 350, height: 325,
				checkbox: true,
				usePager: true,
				async:false,
                alternatingRow: true,//奇偶行显示效果
                columns: [
                    { display: '角色ID', name: 'role_id',  hide : true },
                	{ display: '已选角色', name: 'caption', width: 200, align: 'left' }
                ]               
           	});
            	
			roleAllJsonObj.methodname = "listRole";
			roleAllJsonObj.logicdata = "[{\"user_id\":\""+userId+"\",\"name\":\"\"}]";
			
			userAllRoleGrid = $("#userAllRoleGrid").ligerGrid({
	            	url: _url, parms: roleAllJsonObj, async:false,
					width: 350, height: 325,
					checkbox: true, usePager:true,
	                alternatingRow: true,//奇偶行显示效果
	                columns: [
	                    { display: '用户ID', name: 'role_id',hide : true },
	                	{ display: '可选角色', name: 'caption', width: 200, align: 'left' }
	                ]
            	});
        }
        
        //用户选择角色窗口 按钮取消
        function cancelShowUserRole(){
        	winUserAndRole.hide();
        }
        
        //用户添加角色
        function userRoleAdd(){
        	var tempGridDatas = userAllRoleGrid.getCheckedRows();
        	var text = "";
        	for(var i=0;i<tempGridDatas.length;i++){
        		text += tempGridDatas[i].role_id+",";
        	}
        	if(tempGridDatas.length>0){
				roleControlJsonObj.methodname = "saveRole";
				roleControlJsonObj.logicdata = "[{\"user_id\":\""+globleUserId+"\",\"role_id\":\""+text.substring(0,text.length-1)+"\"}]";
				callserver(roleControlJsonObj,userRoleAddSuc,userRoleAddErr);
			} else {
				warningTip("请选择右侧列表中数据");
			}
        }
        function userRoleAddSuc(){
        	succMsgTip("添加成功");
        	userHaveRoleGrid.loadData();
        	roleAllJsonObj.methodname = "listRole";
			roleAllJsonObj.logicdata = "[{\"user_id\":\""+globleUserId+"\",\"name\":\"\"}]";
        	userAllRoleGrid.loadData();
        }
        function userRoleAddErr(){
        }
        
        //用户移除角色
        function userRoleRemove(){
        	var tempGridDatas = userHaveRoleGrid.getCheckedRows();
        	var text = "";
        	for(var i=0;i<tempGridDatas.length;i++){
        		text += tempGridDatas[i].role_id+",";
        	}
        	
        	if(tempGridDatas.length>0){
				roleAllJsonObj.methodname = "delRole";
				roleAllJsonObj.logicdata = "[{\"user_id\":\""+globleUserId+"\",\"role_id\":\""+text.substring(0,text.length-1)+"\"}]";
				callserver(roleAllJsonObj,userRoleRemoveSuc,userRoleRemoveErr);
			} else {
				warningTip("请选择左侧列表中数据");
			}
        }
        function userRoleRemoveSuc(){
        	userHaveRoleGrid.loadData();
        	roleAllJsonObj.methodname = "listRole";
			roleAllJsonObj.logicdata = "[{\"user_id\":\""+globleUserId+"\",\"name\":\"\"}]";
        	userAllRoleGrid.loadData();
        }
        function userRoleRemoveErr(){
        }
        
        
        //查询所有角色
        function userRoleSearch(){
			roleAllJsonObj.methodname = "listRole";
			roleAllJsonObj.logicdata = "[{\"user_id\":\""+globleUserId+"\",\"name\":\""+$("#searchRoleName").val()+"\"}]";
			callserver(roleAllJsonObj,userRoleSearchSuc,userRoleSearchErr);
        }
        //用户查询成功
        function userRoleSearchSuc(){
        	userAllRoleGrid.loadData();
        }
        //用户查询失败
        function userRoleSearchErr(){
        }
        
        //查询所有角色
        function userHaveRoleSearch(){
			roleHaveJsonObj.methodname = "listRole4User";
			roleHaveJsonObj.logicdata = "[{\"user_id\":\""+globleUserId+"\",\"name\":\""+$("#searchHaveRoleName").val()+"\"}]";
			callserver(roleHaveJsonObj,function(){
	        	userHaveRoleGrid.loadData();
	        },function(){});
        }
        
        /*
         * 用户选择菜单
         */
        var menuWin = null;
        function showUserMenu(id){
        	var param = {
				"classname": "com.wxtf.platform.plugins.permissions.PermissionsAction",
				"methodname": "listMenu",
				"logicdata": '[{"userId":"' + id + '"}]',
				"extenddata": []
			};
			
        	//定义菜单tree
            var menuTree = $("#menuTree").ligerTree({ checkbox: true, nodeWidth: 250 });
            menuTree.clear();
            menuTree.loadData('', _url, param);
        	
        	if(menuWin == null){
        		menuWin = initWindowByDiv('menuDiv','选择菜单', 500, 428, function(item, dialog){
        			var ids = '';
	            	var obj = menuTree.getCheckeds(); 
	            	for(var i=0; i<obj.length; i++){
	            		ids += obj[i].data.id + ',';
	            	}
	            	if(ids == ''){
	            		ids = '';
	            	} else {
	            		ids = ids.substr(0, ids.length - 1);
	            	}
        			
        			param.classname = "com.wxtf.platform.plugins.user.UserAction";
					param.methodname = "saveMenu";
					param.logicdata = '[{"userId":"' + id + '","permissionId":"' + ids + '"}]';
        			callserver(param, function(data, satus){
						succMsgTip(data.resultrecord);
						dialog.hide();
					},function(data, satus){
						warningTip(data.resultrecord);
					});
        		}, closeWin);
        	} else {
        		menuWin.show();
        	}
        }
        
        
        function userPasswordReset(){
        	var userIds = getUserIds(true);
			if(userIds == ""){
				warningTip('请至少选则一个用户进行操作');
				return;
			}
			var Names= getUserCaptions();
			$.ligerDialog.confirm('确认进行密码重置操作？密码重置为123456', function (ml) { 
				if(ml==true){
		       		if(userIds!=""){
						updateJsonObj.classname = "com.wxtf.platform.plugins.user.UserAction";
						updateJsonObj.methodname = "passwordReset";
						updateJsonObj.logicdata = "[{\"ids\":\""+userIds+"\"}]";
						updateJsonObj.extenddata = "[]";
						callserver(updateJsonObj,formUserPassResSuc,formUserPassResErr);
					}
				}
			});
			
        }
        
        function formUserPassResSuc(){
        	var userNames =  getUserCaptions();
        	userGrid.loadData();
			succMsgTip('用户密码重置成功');
        }
        function formUserPassResErr(){
        	var userNames =  getUserCaptions();
        	userGrid.loadData();
			warningTip('用户密码重置失败');
        }
        
        function tallSearch(){
        	if(winTallSearch==null){
	            winTallSearch = initWindowByDiv('tallSearch','高级查询', 620, 454,controlTallSearch,closeWin);
			}else{
				winTallSearch.show();
			}
        }
        
        //弹窗调用确定按钮的方法
        function controlTallSearch(){
        	var tableName = "";
        	var objArrayOne = $("[name=luojiOne]");
        	var objArrayTwo = $("[name=luojiTwo]");
        	var arrayColsName = $("[name=colsName]");
        	var arrayColsValue = $("[name=colsValue]");
        	
        	var tempSearch = "";
        	for(var i=0;i<arrayColsName.length;i++){
        		var conditionValue = objArrayOne[i+1].value;
        		if(conditionValue=="like"){
		        	arraySerarchList.push(objArrayTwo[i+1].value+" "+tableName+arrayColsName[i].value+" "+objArrayOne[i+1].value+" '%"+arrayColsValue[i].value+"%' ");
        		}else if(conditionValue=="in"){
        			var strArr = arrayColsValue[i].value.split(",");
        			var tempStr = "";
        			for(var j=0;j<strArr.length;j++){
        				tempStr +="'"+strArr[j]+"',";
        			}
		        	arraySerarchList.push(objArrayTwo[i+1].value+" "+tableName+arrayColsName[i].value+" "+objArrayOne[i+1].value+" ("+tempStr.substring(0,tempStr.length-1)+") ");
        		}else if(conditionValue=="between"){
        			var strArr = arrayColsValue[i].value.split(",");
		        	arraySerarchList.push(objArrayTwo[i+1].value+" "+tableName+arrayColsName[i].value+" "+objArrayOne[i+1].value+" '"+strArr[0]+"' and '"+strArr[1]+"' ");
        		}else if(conditionValue=="is null"){
		        	arraySerarchList.push(objArrayTwo[i+1].value+" "+tableName+arrayColsName[i].value+" "+objArrayOne[i+1].value+" ");
        		}else{
		        	arraySerarchList.push(objArrayTwo[i+1].value+" "+tableName+arrayColsName[i].value+" "+objArrayOne[i+1].value+" '"+arrayColsValue[i].value+"' ");
        		}
        	}
        	
        	var whereAnd = "";
        	
        	for(var i=0;i<arraySerarchList.length;i++){
        		whereAnd += arraySerarchList[i];
        	}
        	
        	searchJsonObj.classname = "com.wxtf.platform.plugins.user.UserAction";
			searchJsonObj.methodname = "queryPage";
			searchJsonObj.extenddata = "[{\"sWhere\":\""+whereAnd+"\"}]";
			searchJsonObj.logicdata = "[]";
        	callserver(searchJsonObj,formUserSearchSuc,formUserSearchErr);
        	
        	arraySerarchList.length=0;
        	winTallSearch.hide();
        }
        
        //动态给table添加一个tr
        function tallSearchCols(clValue){
        	 var clName = $("option[value='"+clValue+"']").eq(0).text()
        	 if(clValue=="t_user_info.user_birthday"){
				 $("#appendTable").append('<tr style="height:26px;"><td width="60px"><input name="colsName"  type="hidden" value="'+clValue+'">'+clName+'</td><td width="120px">'+$("#condition").html()+'</td><td width="150px"><input name="colsValue" class="times" type="text"></td><td width="90px">'+$("#conditionAnd").html()+'</td><td width="60px" style="cursor: pointer;" onClick="getDel(this)">删除</td></tr>');
				 $(".times").ligerDateEditor({width :120});
        	 }else if(clValue=="t_user_info.user_sex"){
				 $("#appendTable").append('<tr style="height:26px;"><td width="60px"><input name="colsName"  type="hidden" value="'+clValue+'">'+clName+'</td><td width="120px">'+$("#condition").html()+'</td><td width="150px"><select name="colsValue" type="text" style="width:120px"><option value="N">男</option><option value="Y">女</option></select></td><td>'+$("#conditionAnd").html()+'</td><td style="cursor: pointer;" width="60px" onClick="getDel(this)">删除</td></tr>');
        	 }else{
				 $("#appendTable").append('<tr style="height:26px;"><td width="60px"><input name="colsName"  type="hidden" value="'+clValue+'">'+clName+'</td><td width="120px">'+$("#condition").html()+'</td><td width="150px"><input name="colsValue" type="text" style="width:120px"></td><td width="90px">'+$("#conditionAnd").html()+'</td><td width="60px" style="cursor: pointer;" onClick="getDel(this)">删除</td></tr>');
        	 }
        }
        function getDel(va){
			$(va).parent().remove();  
        }
        
	</script>
	</head>

	<body>
		<!-- 将用到的两个常用逻辑运算符初始化在页面中便于上面的使用  -->
		<div style="display: none;" id="condition">
			<select name="luojiOne">
				<option value="=">等于</option>
				<option value="<>">不等于</option>
				<option value=">">大于</option>
				<option value="<"">小于</option>
				<option value="is null">为NULL</option>
				<option value="like">包含</option>
				<option value="in">在...之中(1,2,3)</option>
				<option value="between">在...之间(1,2)</option>
			</select>
		</div>
		<div style="display: none;" id="conditionAnd">
			<select name="luojiTwo">
				<option value="and">与</option>
				<option value="or">或</option>
			</select>
		</div>


		<!-- 高级查询窗口 宽高度已经给好如有需要可根据字段多少自行编排  -->
		<div id="tallSearch" style="display: none;">
			<table width="99%" height="100%">
				<tr>
					<td width="20%">字段列表</td>
					<td width="80%" style="text-algin: center;">
						<table width="100%">
							<tr>
								<td width="60px">字段名称</td>
								<td width="130px">条件匹配</td>
								<td width="150px">字段赋值</td>
								<td width="90px">条件关系</td>
								<td width="60px">移除操作</td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<!-- select中给定的字段为数据库中字段，此处给出表明，是为了后台有多表查询时使用，但是此查询并不适合嵌套查询（子查询） 后台有统一替换过程  -->
					<td width="20%" style="vertical-align: top;">
						<select id="sel" style="height: 356px; width: 82px;" ondblclick="tallSearchCols(this.value);" multiple="multiple">
							<option value="t_user.caption">显示名称</option>
							<option value="t_user.action">登陆账户</option>
							<option value="t_user_info.user_sex">用户性别</option>
							<option value="t_user_info.user_office_tel">办公电话</option>
							<option value="t_user_info.user_mobilephone">移动电话</option>
							<option value="t_user_info.user_tel">家庭电话</option>
							<option value="t_user_info.user_email">用户邮箱</option>
						</select>
					</td>
					<td width="80%" style="text-algin: center;" valign="top">
						<table width="100%" id="appendTable">
						</table>
					</td>
				</tr>
			</table>
		</div>

		<!-- 用户绑定用户组 -->
		<div id="userAndGroup" style="display: none; text-align: center;">
			<br>
			<ul id="userBYGroupTree">
			</ul>
		</div>

		<!-- 用户绑定机构 -->
		<div id="userAndOrg" style="display: none; text-align: center;">
			<br />
			<ul id="userBYOrgTree">
			</ul>
		</div>

		<!-- 用户查询区域 -->
		<div>
			&nbsp;&nbsp;登录账户：<input id="search_loginName" type="text" />
			&nbsp;&nbsp;显示名称：<input type="text" id="search_userName" />
			<button onclick="searchBycols();" class="btn1">查询</button>
			<br />
		</div>

		<!-- 批量添加用户窗口 -->
		<div id="totalUserAdd" style="display: none; text-align: center;">
			<table class="form_table">
				<tr>
					<td>新建数目：</td>
					<td><input id="totalUserAddNum" class="textbg1" onMouseOver="this.style.borderColor='#4fa8e6'" onMouseOut="this.style.borderColor='#A1A3A1'"></td>
					<td><font color="red">*</font></td>
				</tr>
				<tr>
					<td>账户前缀：</td>
					<td><input id="totalUserAddPrefix" class="textbg1" onMouseOver="this.style.borderColor='#4fa8e6'" onMouseOut="this.style.borderColor='#A1A3A1'"></td>
				</tr>
			</table>
		</div>

		<!-- 用户显示角色窗口 -->
		<div id="winUserAndRole" style="display: none;">
			<table align="center">
				<tr>
					<td>
						角色名称：<input type="text" id="searchHaveRoleName">
						<button onclick="userHaveRoleSearch();" class="btn1">查询</button>
						<br>
					</td>
					<td></td>
					<td>
						角色名称：<input type="text" id="searchRoleName">
						<button onclick="userRoleSearch();" class="btn1">查询</button>
						<br>
					</td>
				</tr>
				<tr>
					<td>
						<div id="userHaveRoleGrid"></div>
					</td>
					<td>
						<button onclick="userRoleAdd();" class="btn1">添加</button>
						<br>
						<br>
						<button onclick="userRoleRemove();" class="btn1">移除</button>
					</td>
					<td>
						<div id="userAllRoleGrid"></div>
					</td>
				</tr>
			</table>
		</div>

		<!-- 用户grid显示 -->
		<div id="user_grid"></div>

		<!-- 用户添加form -->
		<div id="userAdd" style="display: none;">
			<form id="user_addform" name="user_addform">
				<input type="hidden" id="f_a_user_id" name="f_a_user_id" value="" />
				<input type="hidden" id="f_a_user_birthday" name="f_a_user_birthday" value="" />
				<input type="hidden" id="f_a_user_fax" name="f_a_user_fax" value="" />
				<input type="hidden" id="f_a_user_address" name="f_a_user_address" value="" />
				<table class="form_table">
					<tr>
						<td colspan="2" height="26px;">
							<font color="red">新建用户密码为:123456</font>
						</td>
					</tr>
					<tr>
						<td class="form_label">登录账户：</td>
						<td><input class="textbg1" type="text" id="f_a_action" onMouseOver="this.style.borderColor='#4fa8e6'" onMouseOut="this.style.borderColor='#A1A3A1'" /></td>
						<td><font color="red">*</font></td>
					</tr>
					<tr>
						<td class="form_label">显示名称：</td>
						<td><input class="textbg1" type="text" id="f_a_caption" onMouseOver="this.style.borderColor='#4fa8e6'"onMouseOut="this.style.borderColor='#A1A3A1'" /></td>
						<td><font color="red">*</font></td>
					</tr>
					<tr>
						<td class="form_label">用户性别：</td>
						<td>
							<select id="f_a_user_sex" style="width: 180px;">
								<option value="N">男</option>
								<option value="Y">女</option>
							</select>
						</td>
					</tr>
					<tr>
						<td class="form_label">移动电话：</td>
						<td><input class="textbg1" type="text" id="f_a_user_mobilephone" onMouseOver="this.style.borderColor='#4fa8e6'" onMouseOut="this.style.borderColor='#A1A3A1'" /></td>
					</tr>
					<tr>
						<td class="form_label">办公电话：</td>
						<td><input class="textbg1" type="text" id="f_a_user_office_tel" onMouseOver="this.style.borderColor='#4fa8e6'" onMouseOut="this.style.borderColor='#A1A3A1'" /></td>
					</tr>
					<tr>
						<td class="form_label">家庭电话：</td>
						<td><input class="textbg1" type="text" id="f_a_user_tel" onMouseOver="this.style.borderColor='#4fa8e6'" onMouseOut="this.style.borderColor='#A1A3A1'" /></td>
					</tr>
					<tr>
						<td class="form_label">用户邮箱：</td>
						<td><input class="textbg1" type="text" id="f_a_user_email" onMouseOver="this.style.borderColor='#4fa8e6'" onMouseOut="this.style.borderColor='#A1A3A1'" /></td>
					</tr>
				</table>
			</form>
		</div>

		<!-- 人员选菜单 -->
		<div id="menuDiv" style="display: none;" >
			<ul id="menuTree"></ul>
		</div>
	</body>
</html>
